package com.itheima.mall.controller;

import com.itheima.mall.pojo.FlashPromotionSession;
import com.itheima.mall.service.SmsFlashPromotionSessionService;
import com.itheima.mall.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flashSession")
public class SmsFlashPromotionSessionController {

    @Autowired
    private SmsFlashPromotionSessionService smsFlashPromotionSessionService;

    /**
     * 获取全部场次
     */
    @GetMapping("/list")
    public ResponseEntity<List<FlashPromotionSession>> listAll() {
        List<FlashPromotionSession> list = smsFlashPromotionSessionService.listAll();
        return ResponseEntity.ok(list);
    }

    /**
     * 获取全部可选场次及其数量
     */
    @GetMapping("/selectList")
    public ResponseEntity<List<FlashPromotionSession>> selectList(Integer flashPromotionId) {
        List<FlashPromotionSession> list = smsFlashPromotionSessionService.selectList(flashPromotionId);
        return ResponseEntity.ok(list);
    }

    /**
     * 添加场次
     */
    @PostMapping("/create")
    public ResponseEntity<String> create(FlashPromotionSession promotionSession) {
        smsFlashPromotionSessionService.create(promotionSession);
        return ResponseEntity.ok("ok");
    }

    /**
     * 删除场次
     */
    @PostMapping("/delete/{id}")
    public ResponseEntity<String> delete(@PathVariable Long id) {
        smsFlashPromotionSessionService.delete(id);
        return ResponseEntity.ok("ok");
    }

    /**
     * 修改启用状态
     */
    @PostMapping("/update/status/{id}")
    public ResponseEntity<String> updateStatus(@PathVariable Long id, @RequestBody Integer status) {
        smsFlashPromotionSessionService.updateStatus(id,status);
        return ResponseEntity.ok("ok");
    }

    /**
     * 修改场次
     */
    @PostMapping("/update/{id}")
    public ResponseEntity<String> update(@PathVariable Long id,@RequestBody FlashPromotionSession promotionSession) {
        smsFlashPromotionSessionService.update(id,promotionSession);
        return ResponseEntity.ok("ok");
    }

    /**
     * 获取场次详情
     */
    @PostMapping("/{id}")
    public ResponseEntity<FlashPromotionSession> flashSession(@PathVariable Long id) {
        FlashPromotionSession flashPromotionSession = smsFlashPromotionSessionService.flashSession(id);
        return ResponseEntity.ok(flashPromotionSession);
    }


}
